package com.example.dw.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.config.exception.GlobalExcetion;
import com.example.dw.DwDataSourceManager;
import com.example.dw.domain.DsNodeSource;
import com.example.dw.service.DsNodeModelService;
import com.example.dw.mapper.DsNodeModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;

/**
* @author CETC
* @description 针对表【ds_node_model】的数据库操作Service实现
* @createDate 2025-11-12 09:19:15
*/
@Service
public class DsNodeModelServiceImpl extends ServiceImpl<DsNodeModelMapper, DsNodeSource>
    implements DsNodeModelService{

    @Autowired
    private DwDataSourceManager dataSourceManager;

    @Override
    public DataSource getDataSourceByDsNodeModelId(String dsNodeModelId) throws GlobalExcetion {
        DsNodeSource dsNodeModel=this.baseMapper.selectById(dsNodeModelId);
        if(dsNodeModel==null){
            throw new GlobalExcetion(1,"数据模型不存在");
        }
        DataSource dataSource=dataSourceManager.getDataSource(dsNodeModel.getModelNo());
        if(dataSource==null){
            throw new GlobalExcetion(1,dsNodeModel.getModelName()+" 数据源为空");
        }
        return dataSource;
    }

    @Override
    public DataSource getDataSourceByDsNodeNo(String dsNodeNo) throws GlobalExcetion {
        return null;
    }
}




